
** Household Size


qui tab numberchildren  

replace numberchildren = 5 if numberchildren >=5 &   numberchildren !=. 
replace otheradults = "6" if otheradults == "More than 6"
replace otheradults = "." if otheradults == "NA"
destring otheradults, replace

gen adults2014 = otheradults2014 + 1
gen adults2015 = otheradults if year == 2015 
replace adults2015 = adults2015 + 1
gen adults2016 = nadults if year == 2016
gen adults2017 =  otheradults if year == 2017
replace adults2017 = adults2017 + 1
gen adults2018 =  otheradults if year == 2018
replace adults2018 = adults2018 + 1

gen adults = adults2014  if year == 2014
replace adults = adults2015 if year == 2015
replace adults = adults2016 if year == 2016
replace adults = adults2017 if year == 2017
replace adults = adults2018 if year == 2018

replace adults = 5 if adults >=5 & adults !=. 

gen adults_nohead = adults - 1

gen weight_adult = 0.5 * adults_nohead
gen weight_kid = 0.3 * numberchildren

gen HHsize = 1 + weight_adult + weight_kid

gen incomeHH = fihhyr2_m / HHsize


*** Mortgage

replace xpmg_m = "." if xpmg_m == "don't know"
replace xpmg_m = "." if xpmg_m == "refused"
replace xpmg_m = "." if xpmg_m == "NA"
replace xpmg_m = "." if xpmg_m == "Don't know"
replace xpmg_m = "." if xpmg_m == "Not applicable"
replace xpmg_m = "." if xpmg_m == "not applicable"
replace xpmg_m = "." if xpmg_m == "Refused"
destring xpmg_m, replace
rename xpmg_m mortgage_m
gen mortgage_y = 12 * mortgage_m 


*** Rent
replace mrent = "." if mrent == "Don't know"
replace mrent = "." if mrent == "NA"
replace mrent = "." if mrent == "Prefer not to state"
destring mrent, replace
gen rent_y = 12 * mrent


**********************
* Wealth 
**********************

qui tab tenure

gen owner = 1 if tenure == "Owned mortgage" | tenure == "Owned outright"
replace owner = 0 if tenure == "Housing association rented" | tenure == "Local authority rented" | tenure == "Private rented"

replace hsval_m = "." if hsval_m == "don't know"
replace hsval_m = "." if hsval_m == "refused"
replace hsval_m = "." if hsval_m == "NA"
replace hsval_m = "." if hsval_m == "Don't know"
replace hsval_m = "." if hsval_m == "not applicable"
replace hsval_m = "." if hsval_m == "Not applicable"
replace hsval_m = "." if hsval_m == "Refused"
destring hsval_m, replace

rename hsval_m homevalue
replace homevalue = 0 if tenure == "Housing association rented" | tenure == "Local authority rented" | tenure == "Private rented"

replace saveamount_m = "." if saveamount_m == "don't know"
replace saveamount_m = "." if saveamount_m == "refused"
replace saveamount_m = "." if saveamount_m == "NA"
destring saveamount, replace

gen saveamount_y = 12 * saveamount_m 

replace nvesttot_m = "." if nvesttot_m == "refused"
replace nvesttot_m = "." if nvesttot_m == "NA"
replace nvesttot_m = "." if nvesttot_m == "Not applicable"
replace nvesttot_m = "." if nvesttot_m == "not applicable"

destring nvesttot_m, replace 
rename nvesttot_m totalsaving

replace ustot_m = "." if ustot_m == "don't know"
replace ustot_m = "." if ustot_m == "refused"
replace ustot_m = "." if ustot_m == "NA"
replace ustot_m = "." if ustot_m == "Don't know"
replace ustot_m = "." if ustot_m == "Not applicable"
replace ustot_m = "." if ustot_m == "not applicable"
replace ustot_m = "." if ustot_m == "Refused"
destring ustot_m, replace
rename ustot_m debtamount


replace xpus_m = "." if xpus_m == "don't know"
replace xpus_m = "." if xpus_m == "refused"
replace xpus_m = "." if xpus_m == "NA"
replace xpus_m = "." if xpus_m == "Don't know"
replace xpus_m = "." if xpus_m == "Not applicable"
replace xpus_m = "." if xpus_m == "not applicable"
replace xpus_m = "." if xpus_m == "Refused"
destring xpus_m, replace
rename xpus_m debt_m
gen debt_y = 12 * debt_m
gen totaldebt = debtamount

replace rent_y = 0 if owner == 1 

replace mortgage_y = 0 if tenure == "Owned outright" | tenure == "Housing association rented" | tenure == "Local authority rented" | tenure == "Private rented" 

replace totaldebt = 0 if us == "0" | us == "No"

gen f_wealth = totalsaving - totaldebt
gen p_wealth = homevalue 

gen f_wealthHH = f_wealth / HH
gen p_wealthHH = p_wealth / HH

gen incomedis = fihhyr2_m - rent_y - mortgage_y
gen incomedisHH = incomedis/ HH


drop if leave == . | female == . | age == . | educ == . | wkstat == . | incomedisHH == . | f_wealth == . | p_wealth == .

rename subsid id
sort id year

bysort id: egen af2 = mean(female)
drop if af2 == .5 
drop af2

egen z_income_disHH = std(incomedisHH)
egen z_f_wealth = std(f_wealthHH)
egen z_p_wealth = std(p_wealthHH)



